﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SanctusSoftware.CcliSongSelectLib
{

    public static class SongSelectDocumentSearcher
    {


        public static SongSelectDocument[] Search(SongSelectDocument[] documents, string title, string author, string theme, string words)
        {

            var results = (IEnumerable<SongSelectDocument>)documents;

            if (!string.IsNullOrEmpty(title))
            {
                results = from d in results
                          where d.Title.ToUpper().Contains(title.ToUpper())
                          select d;
            }

            if (!string.IsNullOrEmpty(author))
            {
                results = from d in results
                          where d.Author.ToUpper().Contains(author.ToUpper())
                          select d;
            }

            if (!string.IsNullOrEmpty(theme))
            {
                results = from d in results
                          where d.Themes.ToUpper().Contains(theme.ToUpper())
                          select d;
            }

            if (!string.IsNullOrEmpty(words))
            {
                results = from d in results
                          where d.Words.ToUpper().Contains(words.ToUpper())
                          select d;
            }

            return results.ToArray<SongSelectDocument>();

        }



    }
}
